<?php


namespace App\Http\Controllers\Platform;


use App\Http\Requests\Platform\AdminMenuRequest;
use App\Services\AdminMenuService;
use App\Services\AdminService;
use App\Utils\ResultUtil;

class MenuController
{
    /**
     * 菜单列表
     * @param AdminMenuService $adminMenuService
     * @param AdminService $adminService
     * @return array
     */
    public function index(AdminMenuService $adminMenuService,AdminService $adminService){
        $menu = $adminMenuService->getTreeList(1,$adminService);
        return ResultUtil::data($menu);
    }


    /**
     * 保存菜单
     * @param AdminMenuRequest $request
     * @param AdminMenuService $menuService
     * @return array
     * @throws \Illuminate\Validation\ValidationException
     */
    public function save(AdminMenuRequest $request,AdminMenuService $menuService){
        $request->scene('add')->validate();
        $data=$request->validationData();
        $menuService->save($data);
        return ResultUtil::success();
    }

    /**
     * 删除菜单
     * @param int $id
     * @param AdminMenuService $adminMenuService
     * @return array
     * @throws \App\Exceptions\ApiException
     */
    public function del(int $id,AdminMenuService $adminMenuService){
        $adminMenuService->del($id);
        return ResultUtil::success();
    }
}
